package com.ronan.imserver.processor;

import com.google.protobuf.MessageLite;
import com.ronan.common.proto.Business;
import com.ronan.common.proto.Heart;
import com.ronan.common.proto.Login;
import com.ronan.common.proto.Message;

/**
 * FileName    : com.ronan.imserver.processor
 * Description : 维护消息类型与对应的处理器
 *
 * @author : ronan
 * @version : 1.0
 * Create Date : 2021/2/26 10:42
 **/
public enum RIMProcessorManager {

    LOGIN(Login.class, new LoginProcessor(), "登录处理器"),
    HEART(Heart.class, new HeartProcessor(), "心跳处理器"),
    MESSAGE(Message.class, new MessageProcessor(), "推送消息处理器"),
    BUSINESS(Business.class, new BusinessProcessor(), "业务数据处理器");

    private final Class<? extends MessageLite> clazz;
    private final RIMProcessor processor;
    private final String desc;

    RIMProcessorManager(Class<? extends MessageLite> clazz, RIMProcessor processor, String desc) {
        this.clazz = clazz;
        this.processor = processor;
        this.desc = desc;
    }

    public static RIMProcessor chooseProcessor(MessageLite clazz) {
        for (RIMProcessorManager value : RIMProcessorManager.values()) {
            if (value.clazz == clazz.getClass()) {
                return value.processor;
            }
        }
        return null;
    }
}
